home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Arashi 1.1 / Game Source / jam src / GamePause.c < prev    next >
Text File  |  1993-03-21  |  4KB  |  205 lines

  1. /*/
  2.      Project Arashi: GamePause.c
  3.      Major release: Version 1.1, 7/22/92
  4.  
  5.      Last modification: Sunday, March 21, 1993, 15:17
  6.      Created: Wednesday, October 9, 1991, 23:45
  7.  
  8.      Copyright © 1991-1993, Juri Munkki
  9. /*/
  10.  
  11. #include <VA.h>
  12. #include "STORM.h"
  13. #include "GamePause.h"
  14. #include "PlayOptions.h"
  15. #include "loadsave.h"
  16. #include "heroflags.h"
  17.  
  18. Rect    VAfullframe;
  19.  
  20. extern    int                ScoretoBeatIndex;    /* mz */
  21.  
  22. extern    EventRecord        Event;
  23. extern    WindowPtr        BackdropWind;
  24.  
  25. extern    Player            Hero;        /* mz */
  26.  
  27. extern    Point            CenterMouse;
  28. extern    void            GetSetMouse(Point *where);
  29.  
  30. extern    int                PlayKeyCodes[];        /*    right, left, fire, zap    */
  31.  
  32. #define    PAUSEDIALOG    129
  33. enum    {    EndPauseButton = 1, RememberKeysButton,
  34.             RotateRightRadio = 5, RotateLeftRadio,
  35.             FireRadio, SuperZapRadio, SaveGame};
  36.  
  37. /* typedef struct{
  38.         int        lvnum;
  39.         int        lvType;
  40.         long    score;
  41.         int        lives;
  42.         long    freelives;
  43.         int        ShowFuseScores;
  44.         int        RestartMode;
  45.         int        Flags;
  46.         int        NumZaps;
  47.         } **GameRecHand, GameRec; */
  48.         
  49. void    GamePauseCleanup()
  50. {
  51.     Point        NoWhere;
  52.     long        EndTime;
  53.  
  54.     NoWhere = CenterMouse;
  55.     GetSetMouse(&NoWhere);
  56.     Delay(5,&EndTime);
  57.  
  58.     VA.color = 0;
  59.     RedrawField();
  60.     RedrawSpikes();
  61.     DisplayLives();
  62. }
  63.  
  64. void    GamePause(cleanup)
  65. int        cleanup;
  66. {
  67.     DialogPtr    PauseDialog;
  68.     DialogPtr    DialogHit;
  69.     int            ItemHit;
  70.     int            ColorStatus = -1;
  71.     int            KeyToChange;
  72.     long        KeyRecord[4];
  73.     int            WhichKey;
  74.     int            k; /* mz */
  75.     int            i;    /* mz */
  76.     Rect        tmpRect = VA.frame;
  77.     
  78.     HideWindow(BackdropWind);
  79.     HideWindow(VA.window);
  80.     VARestoreColors();
  81.  
  82.     PauseDialog = GetNewDialog(PAUSEDIALOG,0,(WindowPtr)-1);
  83.     CenterWindow(PauseDialog);
  84.     ShowWindow(PauseDialog);
  85.     ShowCursor();
  86.     ItemHit = 0;
  87.     KeyToChange = 1;
  88.     SetItemValue(PauseDialog, RotateLeftRadio, 1);
  89.     
  90.     if(cleanup != GameRunning)
  91.         SetItemEnable(PauseDialog, SaveGame, 255);
  92.         
  93.     
  94.     
  95.     do
  96.     {    if(((*(*((GDHandle)VA.device))->gdPMap)->pixelSize == 8) != ColorStatus)
  97.         {    ColorStatus = !ColorStatus;
  98.             SetItemEnable(PauseDialog, EndPauseButton, ColorStatus ? 0 : 255);
  99.         }
  100.         
  101.         
  102.         GetKeys(&KeyRecord);
  103.         if(KeyRecord[0] || KeyRecord[1] || KeyRecord[2] || KeyRecord[3])
  104.         {    
  105.             for(WhichKey=0;WhichKey<128;WhichKey++)
  106.             {    if(BitTst(&KeyRecord,WhichKey))
  107.                 {    WhichKey+=1000;
  108.                 }
  109.             }
  110.             
  111.             if(WhichKey > 1000)
  112.             {    PlayKeyCodes[KeyToChange] = WhichKey-1001;
  113.                 SetItemValue(PauseDialog, RotateRightRadio+KeyToChange, 0);
  114.                 SetItemValue(PauseDialog, RotateRightRadio+KeyToChange, 1);
  115.             }
  116.         }
  117.         
  118.         if(GetNextEvent(everyEvent,&Event))
  119.         {    if(IsDialogEvent(&Event) && Event.what != keyDown)
  120.             {    if(!DialogSelect(&Event,&DialogHit,&ItemHit))
  121.                     ItemHit=0;
  122.                 else
  123.                 {    switch(ItemHit)
  124.                     {    case RotateRightRadio:
  125.                         case RotateLeftRadio:
  126.                         case FireRadio:
  127.                         case SuperZapRadio:
  128.                             SetItemValue(PauseDialog, RotateRightRadio+KeyToChange, 0);
  129.                             KeyToChange = ItemHit - RotateRightRadio;
  130.                             SetItemValue(PauseDialog, RotateRightRadio+KeyToChange, 1);
  131.                             break;
  132.                         case RememberKeysButton:
  133.                             {    Handle    TheKeys;
  134.                             
  135.                                 TheKeys = GetResource('KEYS',128);
  136.                                 BlockMove(PlayKeyCodes,*TheKeys,8);
  137.                                 ChangedResource(TheKeys);
  138.                                 WriteResource(TheKeys);
  139.                                 
  140.                             }
  141.                             break;
  142.                         case SaveGame:
  143.                                 SaveGameF();
  144.                             break;
  145.                     }
  146.                 }
  147.             }
  148.         }
  149.     } while(ItemHit != EndPauseButton);
  150.     
  151.     HideCursor();
  152.     ShowWindow(BackdropWind);
  153.  
  154.     DisposDialog(PauseDialog);
  155.     ShowWindow(VA.window);
  156.     RectRgn(VA.window->visRgn,&VA.window->portRect);
  157.     SetPort(VA.window);
  158.  
  159.     {
  160.         int        oldBackTasks = PlayOptions->noBackgroundTasks;
  161.         
  162.         PlayOptions->noBackgroundTasks = FALSE;
  163.         for(i=0;i<50;i++)
  164.         {    GameEvent();
  165.         }
  166.         PlayOptions->noBackgroundTasks = oldBackTasks;
  167.     }
  168.     
  169.     VAEraseBuffer();
  170.     
  171.     if((cleanup != LevelSelectRunning) && (cleanup != TitlesRunning))
  172.     {
  173.         VA.segmscale=(VA.frame.bottom>>6);            /* mz */
  174.         if(VA.segmscale<1) VA.segmscale=1;
  175.         k=VA.color;
  176.         VA.color=BG2;
  177.         VADrawNumber(ThisLevel.lvNumber,VA.frame.right/2-VA.segmscale-3,VA.segmscale*2+4);
  178.         VA.color=k;
  179.     }
  180.     
  181.     
  182.     switch(cleanup)
  183.     {    case GameRunning:
  184.             GamePauseCleanup();
  185.             break;
  186.         case FlythruRunning:
  187.             DisplayLives();                    
  188.         case LevelSelectRunning:
  189.             {    Point        NoWhere;
  190.                 long        EndTime;
  191.             
  192.                 NoWhere = CenterMouse;
  193.                 GetSetMouse(&NoWhere);
  194.                 Delay(5,&EndTime);
  195.             }
  196.             break;
  197.     }
  198.     
  199.     VACatchUp();
  200.     VAStep();
  201.     
  202.     Event.what = 0;
  203.     Event.modifiers = btnState;
  204. }
  205.